home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
016a
/
4date.zip
/
4DATE.DOC
< prev
Wrap
Text File
|
1991-10-31
|
8KB
|
215 lines
4DATE
by
Marshall Giguere
October 28, 1991
Last revised: October 31, 1991
4DATE provides a somewhat useful set of date computation functions
for 4DOS version 4.xx.
4DATE encapsulates the complete set of supplied functions in one .BTM
file. I choose this as opposed to scattering things to the four
corners of the world, it takes up less total disk space being in one
file and doesn't take up alias space either. In order to accomplish
this 4DATE incorporates a primitive dispatching mechanism for
selecting the called function.
4DATE functions are broken into two categories: User, and Primitive.
User functions display the values they return. Primitive functions
are just that, they perform a computation and return a result that is
useful for either further computation, or display.
4DATE calling and return conventions
All 4DATE functions are enclosed within the file 4DATE.BTM. Each
function is called by passing its name and any arguments to 4DATE:
4DATE function-name arg...
where function-name is the name of the function to perform and arg...
is an optional list of argument values.
All 4DATE primitive functions return their values to the current
environment in the named variable "_$". This allows you to reuse the
result of a 4DATE computation in another computation or whatever your
little heart desires. As an example the 4DATE function CJUL returns
the "Julian" day for a specified year in the variable "_$".
4DATE CJUL %_DATE^ECHO %_$
Typing the above command will display the "Julian" date for the
currently set system date. It should be further noted that ALL USER
functions call a Primitive function to do their task. This has the
desirable side-effect of also returning the displayed value in the
return variable "%_$".
4DATE Available Functions
4DATE provides the following functions:
CJUL - 4DATE CJUL date (Primitive function)
Return the "Julian" day of year for the specified date.
DDATE - 4DATE DDATE integer [aDate] (Primitive function)
DeltaDate returns the actual date for a given
number of days before or after a given date.
DIFF - 4DATE DIFF date1 date2 (Primitive function)
Compute the absolute difference between two dates.
DJD - 4DATE DJD julianDate [year] (User level function)
Display Julian date as calendar Date. If no year is
specified the current year is assumed.
DSTRUCT - 4DATE DSTRUCT date dv1 dv2 dv3 (Primitive function)
Takes a date and returns with the given environment
variables set to date values.
DOW - 4DATE DOW [date [century]] (Primitive function)
Uses Zellers congruence to compute the day-of-the-week.
U.S. date format assumed (see function for changing this).
FDOW - Fast Day-Of-Week (Primitive function)
CAUTION - this function may leave system date
in an incorrect state if interrupted.
HELP - Displays this page.
IS - 4DATE IS integer (User level function)
Displays the date for the given number of
days into the past or future from today.
J2D - 4DATE J2D julianDate [year] (Primitive function)
Converts a Julian day to a calendar date.
The current year is the default.
JDAY - 4DATE JDAY (User level function)
Displays todays "Julian" day of the year.
The choice of names is I admit somewhat idiosyncratic but coming up
with names is an idiosyncratic process at best.
It is arguable as to the "real" need for the existence of User level
functions at all, however, I found myself doing those operations so
often the long way that it seemed reasonable to add them as user
functions. It is of course entirely possible to add the same
functionality via a set of aliases. As an example JDAY could have
been implemented with the following alias:
JDAY=`4DATE CJUL %_date^ECHO Julian date: %_$`
Efficiency & 4DATE
It is provably true that the above alias would be faster than the
current method of invoking another copy of 4DATE. The recursive call
costs roughly double the time of the above alias not to mention the
memory cost of loading two copies of the .BTM into memory. The
disadvantages of the alias approach are primarily: containing the
implementation in one space, and loss of alias space. You can in
fact create the above alias and get the speed without conflicting
with, or changing the implementation package, again at the cost of
using alias space.
What we are dealing here is the classic devils choice, do I want
speed, or space and where? My reason for avoiding the use of aliases
is primarily to accomplish my goal of a single implementation space
and to keep the use of disk real estate efficient. My DOS system
allocates files using 2048 byte clusters. My current 4DATE spans 4
clusters, had I opted for each function in a separate file 11
clusters minimum would have been allocated for a total of 22,528 vs.
8,192. What can I say MS-DOS has a miserable mechanism for managing
the large number of relatively small files that tend to accumulate on
typical system. It should also be noted that some of the 4DATE
functions cannot be implemented as aliases due to their length.
What it all boils down to is that efficiency is what you perceive it
to be for a given context. There is no absolute efficiency, just as
there is no absolute time. Efficiency depends on what your goals and
constraints make it. Fast implementations tend to be inefficient in
their use of space, compact implementations tend to be iteratively
slow. My choices were based on my analysis that alias space is more
limited than transient program space and 4DATE is fast enough for all
practical purposes that loading a second copy of 4DATE would only be
detectable on a slow machine (disk caching helps tremendously).
EXAMPLES
--------
Show the day-of-the-week for today*:
C:\BIN >4DATE DOW^ECHO %_$
Mon
C:\BIN >
---------------
Show the day-of-the-week for Jan. 1, 1991:
C:\BIN >4DATE DOW 01-01-91^ECHO %_$
Tue
C:\BIN >
---------------
Show the Julian date for today*:
C:\BIN >4DATE JDAY
Julian date: 301
C:\BIN >
---------------
Display the date for the day 5 days from today*:
C:\BIN >4DATE IS 5
Date is: 11-02-91
C:\BIN >
---------------
Display the date for the day 5 days before today*:
C:\BIN >4DATE IS -5
Date is: 10-23-91
C:\BIN >
----------------
*note: today = 10-28-91
Conclusion
----------
One might certainly ask why do this at all? And I could say why not,
but that begs the question. There are a large number of tasks in the
arena of system administration that can only be accomplished with the
ability to do some kind of date computation and manipulation, not to
mention the simple problem of managing your own time schedule and DOS
in general lacks any useful date manipulation features. Also I gotta
say it was just plain fun seeing how much I could squeeze out of 4DOS
(take a look at the implementation of Zeller's congruence).
Acknowledgements
----------------
The implementation of Zeller's Congruence is based on the one
published by Jeff Duntemann in the October 1990 issue of Dr. Dobb's
Journal.
Rex Conn for implementing my suggestion on indirect addressing for
environment variables in 4DOS, without which Zeller's Congruence would
have been a lot more difficult, thanks Rex.
J.P. Software in general for creating 4DOS and listening to my
endless enhancement requests and providing help and suggestions.